<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<tpl> $NCharset </tpl>" />
<title><tpl> $langCShopNCSystem </tpl></title>
<tpl>include file ='sys_head_config.html'</tpl>
</head>
<body>
<div class="tabbar">
  <ul class="tab_btns" id="COPYYH2">
    <li class="current"><a href="channel.manage.php?action=index_set"><span><tpl> $langChannelIndexSet </tpl></span></a></li>
  </ul>
	<div class="tab_notes" id="copyyh0">
		<ul class="notesbg block"><span><h4><tpl> $langChannelIndexModuleAddDelOperator </tpl></h4></span></ul>
	</div>
	<!-- 显示提示信息 -->
	<div id="message"></div>
	<!-- 显示提示信息end -->
</div>

<div id="product-help" class="admincp_form" style="top:88px;">
<div id="result_content">
	<form action="channel.manage.php?action=index_update" id="form_add" name="form_add" method="post" style=" background-color:#FBFDFC">
	<!-- 标识，主要用于区别首页管理和频道管理读取配置文件的区别，index为首页管理，channel为频道管理 -->
	<input type="hidden" name="channel_read_param" id="channel_read_param" value="index" />
	<table class="from_table">    
		<tr>
		  <th width="20%"><tpl> $langChannelSelectTemplate </tpl>：</th>
			<td align="left">
				<tpl> $path </tpl>
				<select name="channel_temp_name" id="channel_temp_name">
					<tpl> foreach item=one from=$file_array </tpl>
						<tpl> if $one.type eq "file" </tpl>
							<option <tpl> if $template_name eq $one.name </tpl>selected="selected"<tpl> /if </tpl> value="<tpl> $one.name </tpl>"><tpl> $one.name </tpl></option>
						<tpl> /if </tpl>
					<tpl> /foreach </tpl>
				</select>		  </td>
		</tr>
		<tr>
		  <th width="20%"><tpl> $langChannelModule </tpl>：</th>
			<td align="left"  >
				<table border="0" cellpadding="0" cellspacing="0" rules="none" class="tables_table" >
					<!-- 已添加的模块列表 -->
					<tbody id="add_module_sign" align="left">
						<tpl> foreach from=$module_array item=one key=key </tpl>
							<tr><td>
						<span class="btn_left">
							<input id="module_name" class="btn_submit" type='button'  value='<tpl> $key </tpl>' onclick="modi_module('<tpl> $key </tpl>');deleteRow(this);set_module_style('disabled');" style=" width:250px"/>
						</span>
							<input type='hidden' name='<tpl> $key </tpl>' id='<tpl> $key </tpl>' value='<tpl> $one </tpl>'/>
						
							<a href="javascript:;" onclick="javascript: copyToClipboard('<tpl> $key </tpl>')" title="<tpl> $langChannelCopyModuleName </tpl>" class="copy_a_pic"></a>	<a href='javascript:;'  onclick='if($("#add_module")[0].disabled != true){deleteProhibitionElements("<tpl> $key </tpl>");deleteRow(this);}else{alert("<tpl> $langModuleDelWrong </tpl>");}' title="<tpl> $langChannelDelThisModule </tpl>" class="del_a_pic">
							</a> 
							</td></tr>
						<tpl> /foreach </tpl>
					</tbody>
				</table>		  </td>
		</tr>
		<tr>
		  <th width="20%"><tpl> $langChannelModule </tpl>：</th>
			<td align="left">
				<span class="btn_left">
				<input  type="button"  class="btn_submit" value="<tpl> $langChannelAddModule </tpl>" id="add_module" />
			  </span>
				 <tpl> $langChannelNewModuleName </tpl>		  </td>
		</tr>
		<tr>
			<td>
	</td>
		    <td><span class="btn_left">
			<input type="submit" class="btn_submit" value="<tpl> $langChannelSubmit </tpl>" />
			</span>			</td>
		</tr>
  </table>
</form>
</div>
</div>
<!-- 遮罩 -->	
<div id="module_block" style="display:none;"></div>
<!-- 帮助菜单 -->
<tpl> include file='sys_right_help.html' </tpl>
<!-- 帮助菜单END -->
</body>
</html>
<script>
var module_block = $('#module_block')[0];//模块遮罩显示

$(document).ready(function() {
	hideLoading();

	//不准使用的隐藏域，文本域名,数组形式的
	Prohibition = new Array();
	Prohibition[0] = "add_module_sign_num";//新增模块区域的行数，也就是新增模块的
	Prohibition[1] = "add_module";//新增模块按钮
	Prohibition[2] = "body_module";//模块添加区域
	Prohibition[3] = "add_module_sign";//已添加的模块列表区域
	Prohibition[4] = "channel_temp_name";//选择模板
	Prohibition[5] = "|||";//参数分隔符
	//把已有模块的模块标识符附给数组
	<tpl> foreach from=$module_array item=one key=key </tpl>
		var length = Prohibition.length;
		Prohibition[length] = "<tpl> $key </tpl>";
	<tpl> /foreach </tpl>
	
	//提交表单
	var options = {
		beforeSubmit:  function(){showLoading(showSaveText);},
		success:       function(msg){
							hideLoading();
							showMessage(msg.message,msg.type);
							if(msg.type == '1'){
								//生成静态页面
								$.ajax({
									url: "html.manage.php?action=index",
									data: "",
									type:'post',
									dataType:"json"
								});
							}
						},
		type:      'post',
		dataType:  'json'
	};
	
	//对添加表单做的验证定义
	$("#form_add").validate({
		errorClass: "wrong",
		rules: {
		},
		messages: {
		},
		submitHandler: function() {
			$('#form_add').ajaxSubmit(options);
		}
	});
	
	//添加频道模块
	$('#add_module').click(function(e){
	
		$.blockUI(module_block, { width: '565px', height:'385px', top:'80px', left:'20%', padding:'10px' });//遮罩
		
		$('#module_block').html("<span style='font-size: 12px; font-weight:bold; color:#007DC6; textAlign:left'><tpl> $langChannelModule </tpl>：</span><tr><td align='left'><select name='body_select_module' id='body_select_module' onchange='change_module(this.value);ajax_get_module(this.value)'><option value='adv_module'><tpl> $langChannelAdv </tpl></option><option value='vote_module'><tpl> $langChannelVote </tpl></option><option value='product_module'><tpl> $langChannelMerchandise </tpl></option><option value='shop_module'><tpl> $langChannelShop </tpl></option><option value='pclass_module'><tpl> $langChannelMerchandiseType </tpl></option><option value='shopclass_module'><tpl> $langChannelShopType </tpl></option></select></td><td><input type='button' value='<tpl> $langChannelDel </tpl>' onclick='deleteRow(this);set_module_style(\"no_disabled\");' /></td><div id='adv_module' style='display:none'></div><div id='vote_module' style='display:none'></div><div id='product_module' style='display:none'></div><div id='shop_module' style='display:none'></div><div id='pclass_module' style='display:none'></div><div id='shopclass_module' style='display:none'></div></td></tr>");
		//禁止增加按钮
		$("#add_module").attr("disabled","disabled");
		//显示第一个值的页面
		change_module($("#body_select_module option:selected").val());
		//取模块页面
		ajax_get_module($("#body_select_module option:selected").val());
		//禁止已经存在的模块按钮
		set_module_style("disabled");
	});
});

//删除模块行
function deleteRow(elem) {

	//去除遮罩
	$.unblockUI();
	
	// 先抓到是哪一個 tr
	var row = $(elem).parent().parent();
	// 移除它
	row.fadeOut('normal', function() {row.remove();});
	//开放增加按钮
	$("#add_module").attr("disabled","");
}

//切换模块显示
function change_module(str){
	$('#adv_module').html('');
	$('#vote_module').html('');
	$('#product_module').html('');
	$('#shop_module').html('');
	$('#pclass_module').html('');
	$('#shopclass_module').html('');
	
	$('#'+str).slideDown("fast");//展开
}

//发送请求取模块页面
function ajax_get_module(str){
	$.ajax({
		url: "channel.manage.php",
		data: "action=get_module&module_name="+str,
		type:'post',
		dataType:"html",
		beforeSubmit:  showLoading(showText),   // 提交之前执行的方法
		success: function(msg){
			hideLoading();
			if(msg != ""){
				$("#"+str).html(msg);
			}else{
				$("#"+str).html("<tpl> $langChannelModuleNonentitySelectOther </tpl>");
			}
		}
	});
	return false;
}

//修改模块信息
function modi_module(str){
	
	var temp_name = '';//模块标识符
	
	temp_name_array = str.split("_");//切 标识符名称，'_'分割
	
	var module_name=temp_name_array[0]+'_'+temp_name_array[1];//服务器端程序判断模块名
	
	$.ajax({
		url: "channel.manage.php",
		data: "action=get_module&module_name="+module_name+"&modi_string="+$('#'+str).val(),
		type:'post',
		dataType:"html",
		beforeSubmit:  showLoading(showText),// 提交之前执行的方法
		success: function(msg){
			
			$.blockUI(module_block, { width: '565px', height:'385px',top:'80px', left:'20%', padding:'10px'});//遮罩
			
			deleteProhibitionElements(str);//移除在Prohibition该模块名称
			$("#add_module").attr("disabled","disabled");//禁止模块添加按钮
			hideLoading();
			$('#module_block').html("<span style='font-size: 12px;textAlign:left'><tpl> $langChannelModule </tpl>：</span><tr><td><div id='"+module_name+"' style='display:none'></div></td></tr>");
			change_module(module_name); //显示该模块所在的层
			$("#"+module_name).html(msg); //填充修改信息
		}
	});
	return false;
}

//对于新增模板名称的验证，是否已经重复，如果重复则返回false，如果没有重复则 写入数组Prohibition
function checkRepeatModuleName(name){
	for(index in Prohibition) {
		if(Prohibition[index] == name){
			alert("<tpl> $langChannelModuleIdSelectOtherName </tpl>");
			return false;
		}
	}
	//把新值写入数组Prohibition
	Prohibition[Prohibition.length] = name;	
	return true;
}

//删除Prohibition的元素
function deleteProhibitionElements(elem){//elem为需要删除的元素名
	for(index in Prohibition) {
		if(Prohibition[index] == elem){
			delete Prohibition[index];
			return true;
		}
	}
	return false;
}

//add_module_sign
//当编辑时候将模块按钮设置为不可用
function set_module_style(str){
	if(str=='disabled'){
		$("#add_module_sign input[@type=button]").each(function(){
			$(this).attr('disabled',true);
		})
	}else if(str='no_disabled'){
		$("#add_module_sign input[@type=button]").each(function(){
			$(this).attr('disabled','');
		})
	}
	return false;
}

// js 复制功能 支持 for IE/FireFox/mozilla/ns 
function copyToClipboard(txt){ 
	
     if(window.clipboardData){ 
     	
             window.clipboardData.clearData(); 
             window.clipboardData.setData("Text", txt); 
             
     }else if(navigator.userAgent.indexOf("Opera") != -1){ 
     	
          window.location = txt; 
          
     }else if (window.netscape){ 
     	
          try{
               netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
          }catch(e){ 
               alert("<tpl> $errChannelBrowseWrong </tpl>"); 
          }
          
          var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard); 
          
          if (!clip) {return;}
               
          var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable); 
          
          if (!trans) {return;}
          
          trans.addDataFlavor('text/unicode'); 
          
          var str = new Object(); 
          var len = new Object(); 
          var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString); 
          var copytext = txt; 
          str.data = copytext; 
          trans.setTransferData("text/unicode",str,copytext.length*2); 
          var clipid = Components.interfaces.nsIClipboard; 
          
          if (!clip){return false;}
          clip.setData(trans,null,clipid.kGlobalClipboard); 
     }
}
</script>
